package com.hongshan.wallet.core.trading

import com.hongshan.wallet.BR
import com.hongshan.wallet.MyApplication
import com.hongshan.wallet.R
import com.hongshan.wallet.base.BaseRecyclerAdapter
import com.hongshan.wallet.base.BaseViewHolder
import com.hongshan.wallet.base.MyViewModel
import com.hongshan.wallet.bean.OrderDescBean

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.trading
 * @author   : zhangxx
 * @date     : 2019/3/26
 * @email    : qq957413212@hotmail.com
 * @desc     : //TUDO
 */
class TradingRecycleAdapter(var list: MutableList<OrderDescBean>) : BaseRecyclerAdapter() {

    var refreshListener:(()->Unit)? = null

    override fun getViewModel(holder: BaseViewHolder<MyViewModel>, position: Int): MyViewModel {
        (vmList[position] as TradingRecycleViewModel?)?.stopDown()
        val viewModel = TradingRecycleViewModel(MyApplication.applicationContext)
        viewModel.refresh = { refresh() }
        viewModel.setOrderDescBean(list[position])
        return viewModel
    }

    override fun getLayoutIdForPosition(position: Int) = R.layout.list_item_trading

    override fun initVariableId(position: Int) = BR.vm

    override fun getItemCount(): Int {
        val size = super.getItemCount()
        return if (size == 0) list.size else size
    }

    override fun isEmpty() = list.size == 0

    override fun refresh() {
        super.refresh()
        refreshListener?.invoke()
    }

}